package com.lbd.system.controller;

import com.lbd.system.bean.Recruitment;
import com.lbd.system.service.RecruitmentService;
import com.lbd.base.controller.BaseController;
import com.lbd.commons.Result;
import com.lbd.commons.ResultState;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;


@RestController
@RequestMapping("/recruitment")
public class RecruitmentController extends BaseController {
    private final Logger log = Logger.getLogger(this.getClass());

    @Autowired
    private RecruitmentService recruitmentService;

    /**
     * 按条件分页查询recruitment
     *
     * @param page        第几页
     * @param rows        一页多少条
     * @param recruitment
     * @return
     */
    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public Result list(int page, int rows, Recruitment recruitment) {
        return new Result(ResultState.SUCCESS, "查询成功", recruitmentService.findByPageConditionJpql(page, rows, recruitment));
    }

    /**
     * 保存recruitment信息
     *
     * @param recruitment
     * @return
     */
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Result save(Recruitment recruitment) {
        recruitmentService.save(recruitment);
        return new Result(ResultState.SUCCESS, "添加成功", "");
    }

    /**
     * 根据id查询回显要编辑的Recruitment
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.GET)
    public Result toEdit(String id) {
        return new Result(ResultState.SUCCESS, "加载成功", recruitmentService.findById(id));
    }

    /**
     * 修改recruitment信息
     *
     * @param recruitment
     * @return
     */
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public Result update(Recruitment recruitment) {
        recruitmentService.update(recruitment);
        return new Result(ResultState.SUCCESS, "更新成功");
    }

    /**
     * 删除recruitment信息
     *
     * @param ids
     * @return
     */
    @RequestMapping(value = "/del", method = RequestMethod.POST)
    public Result del(@RequestParam("ids[]") String[] ids) {
        System.out.println(Arrays.toString(ids));
        recruitmentService.del(ids);
        return new Result(ResultState.SUCCESS, "删除成功");

    }

}
